import * as React from 'react';
import { ConfigProvider } from 'antd';
import zh_CN from 'antd/es/locale/zh_CN';
import app from '@/common/core';
import createHistory from '@/common/core/createHistory';
import routes from '@/pages/router';
import { loadLocalConfig } from '@/services/app';

export default async () => {
  const localConfig = await loadLocalConfig();
  Object.defineProperty(window, '__config', {
    configurable: false,
    enumerable: true,
    writable: false,
    value: localConfig,
  });
  const publicModels: string[] = [];
  const dvaApp = app({
    selector: '#root',
    routes,
    publicModels,
    loadModel: (m: string) => import(`./models/${m}`),
    dvaOptions: {
      history: createHistory({
        type: 'browser',
      }),
    },
    root: (n) => <ConfigProvider locale={zh_CN}>{n}</ConfigProvider>,
  });
  dvaApp.setupModels();
  return dvaApp;
};
